package algorithm.sorty.sort.compare;

import algorithm.sorty.Sort;

/**
 * @Description: 选择排序
 * @Author Ammar
 * @Create 2023/5/1 08:17
 */
public class SelectionSort<T extends Comparable<T>> extends Sort<T> {
    @Override
    public void sort() {
        for(int end = array.length - 1; end > 0; end--) {
            int maxIndex = 0;
            for(int begin = 1; begin <= end; begin++) {
                if(compare(maxIndex, begin) <= 0) {
                    maxIndex = begin;
                }
            }
            swap(maxIndex, end);
        }
    }
}
